package Db

import (
	"fmt"
	config "westarry/gin-fox/gin-fox/config"

	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)



func InitDb() *gorm.DB{
	c:=config.InitConfig()
	dsn := c.Db.Username+":"+c.Db.Password+"@tcp("+c.Db.Host+":"+c.Db.Port+")/"+c.Db.Name+"?charset=utf8mb4&parseTime=True&loc=Local"
	Db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		fmt.Printf("[ginfox]数据库连接失败%v\n", err)
	} else {
		fmt.Printf("[ginfox]数据库连接成功\n")
	}
	return Db
}

